<?php


namespace App\Utils\Notice;

use App\Model\NoticeUser;
use App\Constants\Model\Notice as NoticeConstants;
use Hyperf\DbConnection\Model\Model;

/**
 * 审核失败
 * Class UserTaskAuditFail
 * @package App\Utils\NoticeController
 */
class UserTaskAuditFail extends Notice
{
    public $messageTemplate = "您好，您提交的截图未被悬赏主通过，具体原因如下：“%audit_fail_context%}”";
    public $routeName = '/pages/userTasks/detail?id=%task_exec_id%&task_id=%task_id%';

    public function toDatabase()
    {
        $this->data['content'] = isset($this->data['content']) ? $this->data['content'] : [];
        $this->data['routeParams'] = isset($this->data['routeParams']) ? $this->data['routeParams'] : [];

        $data = $this->format($this->data);
        $model = new NoticeUser();
        $model->fill($data)->save();
    }


    public function format(array $data)
    {
        return [
            'user_id' => $this->receiverId,
            'type' => NoticeConstants::USER_TASK_AUDIT_FAIL,
            'content' => $this->sprintf($this->messageTemplate, $data['content']),
            'extension' => [
                'path' => $this->sprintf($this->routeName, $data['routeParams'])
            ]
        ];
    }
}
